package com.example.photography.Activity.order;


import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.core.widget.NestedScrollView;

import com.example.photography.R;
import com.example.photography.adapter.PictuerAdapter;
import com.example.photography.common.BaseActivity;
import com.example.photography.ui.CircleImageView;
import com.example.photography.util.Util;
import com.example.photography.view.MyListView;
import com.google.android.material.bottomsheet.BottomSheetDialog;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 订单发起成功
 */
public class Order_Details extends BaseActivity {


    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.cv_head)
    CircleImageView cvHead;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_identify)
    TextView tvIdentify;
    @BindView(R.id.tv_time)
    TextView tvTime;
    @BindView(R.id.focus)
    TextView focus;
    @BindView(R.id.tv_local)
    TextView tvLocal;
    @BindView(R.id.tv_recruit)
    TextView tvRecruit;
    @BindView(R.id.tv_charge)
    TextView tvCharge;
    @BindView(R.id.tv_demand)
    TextView tvDemand;
    @BindView(R.id.tv_date)
    TextView tvDate;
    @BindView(R.id.tv_site)
    TextView tvSite;
    @BindView(R.id.tv_price)
    TextView tvPrice;

    @BindView(R.id.iv_like)
    ImageView ivLike;
    @BindView(R.id.iv_save)
    ImageView ivSave;
    @BindView(R.id.iv_share)
    ImageView ivShare;
    @BindView(R.id.tv_chat)
    TextView tvChat;
    @BindView(R.id.tv_invite)
    TextView tvInvite;
    @BindView(R.id.ll_bottom)
    RelativeLayout llBottom;
    @BindView(R.id.ns_view)
    NestedScrollView nsView;
    @BindView(R.id.lv_photo)
    MyListView lvPhoto;
    private String local, recruit, charge, demand, date, site, price;
    private List<String> photos;
    private BottomSheetDialog sheelt;

    @Override
    protected void initData() {
        Intent intent = getIntent();
        Bundle bundle = intent.getBundleExtra("data");
        if (bundle != null) {
            ArrayList<String> data = bundle.getStringArrayList("data");
            demand = data.get(0);
            date = data.get(1);
            site = data.get(2);
            price = data.get(3);
            photos = bundle.getStringArrayList("photos");
        }
        initView();
    }

    private void initView() {
        tvTitle.setText("约拍详情");
        tvDemand.setText(demand);
        tvDate.setText(date);
        tvSite.setText(site);
        tvPrice.setText(price);
        PictuerAdapter pictuerAdapter = new PictuerAdapter(photos, this);
        lvPhoto.setAdapter(pictuerAdapter);
        initListen();

    }

    private void initListen() {
        //监听滑动
        nsView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
            @Override
            public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
                /**
                 * 上滑隐藏底部框
                 */
                if (scrollY > oldScrollY) {
                    llBottom.setVisibility(View.GONE);
                } else {
                    llBottom.setVisibility(View.VISIBLE);
                }
            }
        });
        ivBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                removeCurrentActivity();
            }
        });
        ivLike.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ivLike.setImageResource(R.drawable.bottom_like_true);
            }
        });
        ivSave.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ivSave.setImageResource(R.drawable.bottom_save_true);
            }
        });
        ivShare.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                sheelt = new BottomSheetDialog(Order_Details.this);
                View contentView = LayoutInflater.from(Order_Details.this).inflate(R.layout.bottom_share, null);
                sheelt.setContentView(contentView);
                //给布局设置透明背景色
                sheelt.getWindow().findViewById(R.id.design_bottom_sheet).setBackgroundResource(android.R.color.transparent);
                sheelt.show();
                TextView iv_dismiss = contentView.findViewById(R.id.tv_dismiss);
                iv_dismiss.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        sheelt.dismiss();//消失
                    }
                });
            }
        });
        tvChat.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Util.showToast(Order_Details.this, "负责不同版块的开发者正在抓紧对接中~");
            }
        });
        tvInvite.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

            }
        });

    }

    @Override
    protected int getLayoutId() {
        return R.layout.details_order;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        //防止窗体泄漏
        if (sheelt != null) {
            sheelt.dismiss();
        }
    }
}
